package LeetCode._03_链表;

public class _01_两数相加 {
    public class ListNode {
       int val;
       ListNode next;
       ListNode() {}
       ListNode(int val) { this.val = val; }
       ListNode(int val, ListNode next) { this.val = val; this.next = next; }
    }

    public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
        if(l1 == null && l2 == null) return null;
        if(l1 == null) return l2;
        if(l2 == null) return l1;
        ListNode newHead = new ListNode(0);
        ListNode cur = newHead;
        int jinwei = 0;
        while(l1 != null || l2!=null || jinwei!=0){
            int sum = jinwei; //加上上次加法可能产生的进位
            if(l1 != null){
                sum += l1.val;
                l1 = l1.next;
            }
            if(l2!=null){
                sum += l2.val;
                l2 = l2.next;
            }
            jinwei = sum/10; //处理进位
            sum %= 10; //处理可能产生的进位和
            cur.next = new ListNode(sum);
            cur = cur.next;
        }
        return newHead.next;
    }

    public static void main(String[] args) {
        System.out.println(15/10);
        System.out.println(15%10);
    }

}
